import { guID, query } from "@/common.js"
import * as func from "./func.js"
import CusForm from "@/components/CusForm/index.vue"
export default {
  name: '',
  props: {
    modalType: {
      type: [String, Number],
      default: 0, // 0:关闭弹框 1:   2：列表中表单预览   3：编辑预览
    },
    id: {
      type: [String, Number],
      default: '', // 传入的id值
    },
    formArr:  {
      type: Array,
      default: function (){
        return []
      }, // 传入表单json数组
    },
  },
  components: {
    CusForm
  },
  data(){
    return {
      refId: guID(), // 唯一id作为ref，这样一个组件被同一个页面多次调用，生成的ref不一样就能保证，重置和校验表单，不出问题
      operateForm: [],
    }
  },
  methods:{
    ...func
  },
  computed:{
    modalTitle: function(){
      return {1: ``, 2: `表单预览`, 3:`表单预览`}[this.modalType] || ''
    },
    modalType_id_formArr(){
      return { modalType: this.modalType, id: this.id, formArr: this.formArr }
    }
  },
  watch:{
    modalType_id_formArr: function (newVal, oldVal){
      const {modalType, id, formArr} = newVal
      // console.log(modalType)
      if(modalType <= 0) { // 关闭弹窗并且重置掉
        // this.resetForm()
        this.operateForm = []
        query('#previewFormId').scrollTop = 0
      } else if(modalType == 2 || modalType == 3) { // 查询表详情
        if(formArr.length || id) {
          if(formArr.length) {
            this.operateForm = formArr
          } else {
            this.getForm()
          }
        }
      } else if(modalType == 4){ // 待拓展
        // this.edit()
      } else if(modalType == 5) { // 待拓展
        // this.otherFunc()
      }
    },
  },
  created(){
  },
  mounted(){
  },
}